#include "stdafx.h"
#include "Main.h"
AI::AI()
{
	RandomAnimationTimer=Random(5,30);
	RandomMovement=Random(2,5);
	AttackState=2;
}
void AI::Die(int &ID)
{
	PlayRandomAnimation("");
}
void AI::PlayRandomAnimation(Str name)
{
	RandomAnim.New().set(cskel,name).is();
}
void AI::animate()
{
	super::animate();
	REPA(RandomAnim)cskel.animate(RandomAnim[i],true);
}
void AI::create(Str FileName)
{
	Game::ObjParams obj;
	FileText file;
	if(file.read(FileName))
	{
		for(;file.level();)
		{
			if(file.cur("ObjectPath"))obj.load(file.getName());
			if(file.cur("Scale"))obj.scale(file.getInt());
		//	if(file.cur("WalkAnimation"))WalkAnimPath=file.getName();
		//	if(file.cur("IdleAnimation"))StandAnimPath=file.getName();
		//	if(file.cur("RunAnimation"))RunAnimPath=file.getName();
			if(file.cur("Speed"))speed=file.getInt();
		}
	}
	obj.type(true, "OBJ_CHR");
	obj.matrix.pos=Vec(16,0,16);
	super::create(obj);
	move_walking=true; //Set it to walk, Which means it will load sac.walk
}
Bool AI::Alive(){return Health<0;}
Bool AI::update(){
   if(super::update())
   {
	  RandomAnimationTimer-=Time.d();
	  RandomMovement-=Time.d();
	  if(Players.elms())if(Dist(Players[0].pos(),T.pos())<10)
	  {
		  Int ID;
		  MoveTo(Players[0].pos(),ID);
	  }
	  if(Players.elms())if(Dist(Players[0].pos(),T.pos())<2)
	  {
		  Players[0].RecieveDamage(20);
	  }
	  return true;
   } 
   return false;
}	
void AI::MoveTo(Vec &v, int &ID)
{
//	if(T.ID==ID)
	//{
		//if(v!=T.pos())
			actionMoveTo(v);
//	}
}
void AI::Attack(Chr &c, int &ID)
{
	if(T.ID==ID)
	{
	
	}
}
void AI::Draw()
{
	drawPrepare();
}